<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>Cookie 存储</title>
  <link rel="stylesheet" href="./demo.css">
</head>

<body>
  <div id="app">
    <div class="btn" @click="saveCookie">存储cookie</div>
    <div class="btn" @click="getCookie">获取cookie</div>
    <div class="btn" @click="deleteCookie">删除cookie</div>

    <div class="btn" @click="saveCoreCookie">存储大于4KB的cookie</div>

    <div class="cookie">
      {{cookie}}
    </div>
  </div>
  <script src="https://cdn.bootcss.com/js-cookie/latest/js.cookie.js"></script>
  <script src="https://cdn.bootcss.com/vue/2.5.17-beta.0/vue.min.js"></script>
  <script>
    let coreCookie = ''
    for (let i = 0; i < 100; i++) {
      coreCookie += `我是第${i+1}条数据，请多指教`
    }
    let myApp = new Vue({
      el: '#app',
      data: {
        cookie: ''
      },
      methods: {
        saveCookie() {
          Cookies.set('name', 'value', {
            expires: 7,
            path: '',
            domain: ''
          })
        },
        getCookie() {
          this.cookie = Cookies.get('name')
        },
        deleteCookie() {
          Cookies.remove('name', {
            path: ''
          })
        },
        saveCoreCookie() {
          console.log(coreCookie)
          Cookies.set('nameCore', coreCookie, {
            expires: 7,
            path: '',
            domain: ''
          })
        }
      }
    })
  </script>
</body>

</html>